package com.seqb.manage.synthesis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seqb.common.mybatis.WrapperHandler;
import com.seqb.manage.synthesis.dao.SynthesisQuestionDao;
import com.seqb.manage.synthesis.domain.SynthesisQuestionDO;
import com.seqb.manage.synthesis.service.SynthesisQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Map;

/**
 * @author lilinshen
 * @title 综合题
 * @description 请填写相关描述
 * @date 2019-12-05
 */
@Service
public class SynthesisQuestionServiceImpl implements SynthesisQuestionService {
    @Autowired
    private SynthesisQuestionDao synthesisQuestionDao;

    @Override
    public SynthesisQuestionDO get(Long id) {
        return synthesisQuestionDao.selectById(id);
    }

    @Override
    public Page<SynthesisQuestionDO> list(Map<String, Object> map) {
        if (null != map && null != map.get("pageNumber") && null != map.get("pageSize")) {
            PageHelper.startPage(Integer.valueOf(map.get("pageNumber").toString()), Integer.valueOf(map.get("pageSize").toString()));
        } else {
            PageHelper.startPage(1, Integer.MAX_VALUE);
        }
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, SynthesisQuestionDO.class);
        queryWrapper.orderByDesc("id");
        return (Page<SynthesisQuestionDO>) synthesisQuestionDao.selectList(queryWrapper);
    }

    @Override
    public int count(Map<String, Object> map) {
        QueryWrapper queryWrapper = WrapperHandler.genQueryWrapper(map, SynthesisQuestionDO.class);
        return synthesisQuestionDao.selectCount(queryWrapper);
    }

    @Override
    @Transactional
    public int save(SynthesisQuestionDO synthesisQuestion) {
        return synthesisQuestionDao.insert(synthesisQuestion);
    }

    @Override
    @Transactional
    public int update(SynthesisQuestionDO synthesisQuestion) {
        return synthesisQuestionDao.updateById(synthesisQuestion);
    }

    @Override
    @Transactional
    public int remove(Long id) {
        return synthesisQuestionDao.deleteById(id);
    }

    @Override
    @Transactional
    public int batchRemove(Long[] ids) {
        return synthesisQuestionDao.deleteBatchIds(Arrays.asList(ids));
    }

}